package com.weibo.gaollg;

import java.util.Date;
import java.util.List;

import net.vsame.url2sql.domain.Model;
import net.vsame.url2sql.domain.Url2SqlContext;
import net.vsame.url2sql.helper.SqlHelper;
import net.vsame.url2sql.helper.Url2SqlMappingHelper;
import net.vsame.url2sql.helper.WebHelper;

public class EditAction {
	
	private Url2SqlContext context;

	public EditAction(){
		context = WebHelper.getContext();
	}
	
	public void index(){
		List<Model> list = SqlHelper.query("SELECT * from __url2sqlmapping ORDER BY path", null);
		context.putUsefulData("data", list);
	}

	public void addPath(){
		int x = SqlHelper.execute("INSERT INTO __url2sqlmapping(`path`,`v`, `js`, `STATUS`) VALUES(${path}, ${v}, ${js}, ${status})", null);
		context.putUsefulData("data", x);
	}
	
	public void updatePath(){
		int x = SqlHelper.execute("UPDATE __url2sqlmapping set `path`=${path},`v`=${v}, `js`=${js}, `STATUS`=${status} where id=${id}", null);
		context.putUsefulData("data", x);
	}
	
	public void deletePath(){
		int x = SqlHelper.execute("DELETE FROM __url2sqlmapping where id=${id}", null);
		context.putUsefulData("data", x);
	}
	
	@SuppressWarnings("deprecation")
	public void reload(){
		Date date = new Date();
		context.put("time", date.toLocaleString());
		
		Url2SqlMappingHelper.reload();
	}
}
